package dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import domain.Doctor;
import domain.Owner;
import domain.Pet;
import domain.Worker;
import util.C3P0Util;

public class WorkerDaoImpl {
	
	/**
	 * 登录
	 * @param workerAccount
	 * @param workerPassword
	 * @return
	 * @throws SQLException
	 */
	public Worker login(String workerAccount, String workerPassword) throws SQLException{
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());
		return qr.query("select * from worker where workerAccount=? and workerPassword=?", new BeanHandler<Worker>(Worker.class), workerAccount, workerPassword);
	}
	
	/**
	 * 注册
	 * @param worker
	 * @return
	 * @throws SQLException
	 */
	public boolean regist(Worker worker) throws SQLException {
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());
		int rows = qr.update("INSERT INTO worker VALUES(?,?,?,?,?,?,?)",worker.getWorkerId(),worker.getWorkerAccount(), worker.getWorkerPassword(),worker.getWorkerName(),worker.getWorkerPhone(),worker.getWorkerEmail(),worker.getWorkerED());
		if(rows==1){
			return true;
		}
		System.out.println(rows);
		return false;
	}
}
